﻿using System;
using System.Security;
using System.Windows;
using GpgApi;

namespace WgpgGUI
{
    public static class GUIUtils
    {
        public static Func<AskPassphraseInfo, SecureString> AskPassphrase()
        {
            return GUIUtils.AskPassphrase(null);
        }

        public static Func<AskPassphraseInfo, SecureString> AskPassphrase(Window owner)
        {
            return delegate(AskPassphraseInfo info)
            {
                DialogPassphrase p = new DialogPassphrase(owner, info);
                SecureString s = p.ShowDialog() == true ? p.password.SecurePassword : null;

                if (s != null)
                    s.MakeReadOnly();

                return s;
            };
        }
    }
}
